package com.example.qiao.mvp.model;

import com.example.mylibrary.http.RetrofitManager;
import com.example.mylibrary.mvp.model.BaseModel;
import com.example.qiao.api.Api;
import com.example.qiao.bean.GUAN;
import com.example.qiao.bean.Tong;
import com.example.qiao.bean.Zhong;
import com.example.qiao.mvp.contract.PostContract;
import com.google.gson.JsonObject;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okio.BufferedSink;

public class PostModel extends BaseModel implements PostContract.Model {

    @Override
    public void requestGuan(Observer<List<GUAN>> observer){
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("page",1);
        jsonObject.addProperty("userId",0);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"),jsonObject.toString());
        new RetrofitManager().getRetrofit().create(Api.class)
                .guan(requestBody).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);

    }

    @Override
    public void requestZhong(Observer<List<Zhong>> observer) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("page",1);
        jsonObject.addProperty("userId",0);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"),jsonObject.toString());
        new RetrofitManager().getRetrofit().create(Api.class)
                .zhong(requestBody).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void requestTong(Observer<List<Tong>> observer) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("page",1);
        jsonObject.addProperty("userId",0);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"),jsonObject.toString());
        new RetrofitManager().getRetrofit().create(Api.class)
                .tong(requestBody).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
}
